
<?php
require ('includes/config.php');
$page_title = 'Events';
include ('includes/header.php');

if ($_SERVER['REQUEST_METHOD'] == 'POST'){
	$keyword = $_POST['keyword'];
$searchfield = $_POST['searchfield'];	
	}
  
  
  
   
?>
 <!-- fluid body container -->

<div class="container-fluid">
<!--fluid sidebar 3 columns   -->
	<div class="span3">
		<div class="well sidebar-nav">
<?php
require ('includes/side_nav_events.php');
?>
         </div>
    </div>
   <!---end of sidebar 3 columns  -->
  
  <div class="span9">
  		<div class="hero-unit">

<?php   	
  //sets the manager id to empty
   $mid = 24;
	$row = FALSE; // Assume nothing! 
	
if (isset($_GET['det']) && filter_var($_GET['det'], FILTER_VALIDATE_INT, array('min_range' => 1)) ) { // Make sure there's a event ID!
  
		        $eid = $_GET['det'];

				$mid = $_GET['id'];}

    require(MYSQL);  //open database  
   //query to select event details     
   $q= "SELECT `type`,events.id, `ev_id`,`text`,LEFT(`start_date`, 10)`start_date`,RIGHT(`start_date`, 8)`start_time`,RIGHT(`end_date`, 8)`end_time`,CONCAT_WS(' ', ev_manager.f_name,ev_manager.s_name) FROM `events`,ev_manager WHERE events.ev_id = $eid AND ev_manager.id= $mid";     
	$r=mysqli_query($dbc,$q);	
		
		if (mysqli_num_rows($r) == 1) { // one result picked
				
						$row = mysqli_fetch_array ($r, MYSQLI_ASSOC);
	
		echo "<h2>Event - {$row['text']} ({$row['ev_id']})</h2>
				<h4>Date - {$row['start_date']} </h4>
				<h4>Start Time - {$row['start_time']}   End Time - {$row['end_time']}</h4>
				
				<h4>Event Manager - {$row["CONCAT_WS(' ', ev_manager.f_name,ev_manager.s_name)"]}</h4>
		
		"; 
		
		}
		
		$q="SELECT `type`,`id`,`text`,`start_date`,events.ev_id,`stall_id`,`yr_grp`,`description`, `name`,`location`, `notes` FROM `events`,stall WHERE events.ev_id = $eid AND stall.ev_id = $eid";
		$r=mysqli_query($dbc,$q);	
		
     	if (mysqli_num_rows($r) == 0) {	
			echo"<h3>There are no stalls set up for this event, if you would like to set up a  <a href=\"New_stall.php\">stall</a></h3>";
		}
		else{
   
      echo '<table border="1px" width="95%" cellspacing="3" cellpadding="3" align="centre">
	<tr>
		<td align="left" width="10%"><b>Stall-Id</b></td>
		<td align="left" width="20%">Name</td>
		<td align="left" width="20%">Location</td>
		<td align="left" width="8%">Year</td>
		<td align="left" width="30%">Notes</td>
		<td align="left" width="10%"></td>
	</tr>';
   
//print out details of the stalls
   while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {
   echo "<tr>
		<td align=\"left\"> {$row['stall_id']}</td>
		<td align=\"left\">{$row['name']}<br/>{$row['description']}</td>
		<td align=\"left\">{$row['location']}</td>
		<td align=\"left\">{$row['yr_grp']}</td>
		<td align=\"left\"><p>{$row['notes']}</p></td>
		<td align=\"left\"><a href=\"delete.php?eid={$row['ev_id']}\">Delete\n
<a href=\"ammend.php?eid={$row['ev_id']}&id={$row['id']}\">Amend</td>
	</tr>\n";
		

} // End of while loop.

echo '</table>';
		}
mysqli_free_result ($r);
mysqli_close($dbc);
     
		
		
 ?>       
        
    

  
   		 </div>
  <!--end of hero-unit -->
  <!--start of events list -->
  		  <div class="row-fluid">This is where the events list will go
 		   </div>
    </div>
  <!--end of events list -->
<!-- start of left bar to do list -->
 	
    </div>
    <!-- end of to do list-->
    </div>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script src="js/bootstrap.min.js"></script>
	<script src="js/bootstrap.js"></script>
  </body>
</html>
<?php ob_flush(); ?>
